#!/bin/bash

PROJECT_ROOT=$(cd `dirname $0/`/..;pwd)

cd $PROJECT_ROOT

export GO111MODULE=on
export GONOSUMDB=*
export GOPROXY=https://cmc.centralrepo.rnd.huawei.com/cbu-go

cd CacheRedis
go mod tidy
CGO_CFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2" go build -buildmode=pie --ldflags "-s -linkmode 'external' -extldflags '-Wl,-z,now'" main.go

cd $PROJECT_ROOT
cd NosqlMongo
go mod tidy
CGO_CFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2" go build -buildmode=pie --ldflags "-s -linkmode 'external' -extldflags '-Wl,-z,now'" main.go

cd $PROJECT_ROOT
cd RDSMySQL
go mod tidy
CGO_CFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2" go build -buildmode=pie --ldflags "-s -linkmode 'external' -extldflags '-Wl,-z,now'" main.go

cd $PROJECT_ROOT
cd RDSPostgreSQL
go mod tidy
CGO_CFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2" go build -buildmode=pie --ldflags "-s -linkmode 'external' -extldflags '-Wl,-z,now'" main.go

cd $PROJECT_ROOT
cd RDSSQLServer
go mod tidy
CGO_CFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2" go build -buildmode=pie --ldflags "-s -linkmode 'external' -extldflags '-Wl,-z,now'" main.go

cd $PROJECT_ROOT
cd DMSKafka
go mod tidy
CGO_CFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2" go build -buildmode=pie --ldflags "-s -linkmode 'external' -extldflags '-Wl,-z,now'" main.go

cd $PROJECT_ROOT
cd RDSSQLServer
go mod tidy
CGO_CFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2" go build -buildmode=pie --ldflags "-s -linkmode 'external' -extldflags '-Wl,-z,now'" main.go

cd $PROJECT_ROOT
cd RDSSQLServer
go mod tidy
CGO_CFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2" go build -buildmode=pie --ldflags "-s -linkmode 'external' -extldflags '-Wl,-z,now'" main.go

tar -czvf $PROJECT_ROOT/huaweicloud-go-quickstart-service-samples-${CID_BUILD_TIME}.tar.gz . --exclude=.cid --exclude=.codecheck
